package com.ygqh.baby.observer;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Observable;
import java.util.Observer;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.ygqh.baby.ao.CodeType;
import com.ygqh.baby.ao.PayType;
import com.ygqh.baby.observer.Observable.OrderCancelObservable;
import com.ygqh.baby.observer.Observable.OrderPaySuccessObservable;
import com.ygqh.baby.po.YgOrderPayment;
import com.ygqh.baby.service.ScheduleJobService;
import com.ygqh.baby.service.YgFrameCodeService;
import com.ygqh.baby.service.YgOrderPaymentService;
import com.ygqh.baby.service.YgOrderService;
import com.ygqh.baby.service.alipay.api.AlipayApi;
import com.ygqh.baby.service.alipay.api.DeclareCustomsModel;
import com.ygqh.baby.service.trustone.TrustoneConfig;
import com.ygqh.baby.utils.DateConvertUtils;

@Deprecated
@Component
public class TrustoneOrderPaidOrCancelObserver implements Observer {

	private Logger logger = Logger.getLogger(this.getClass());
	@Autowired
	private ScheduleJobService scheduleJobService;
	@Autowired
	private YgOrderPaymentService ygOrderPaymentService;
	@Autowired
	private AlipayApi alipayApi;
	@Autowired
	private YgOrderService ygOrderService;
	@Autowired
	private YgFrameCodeService ygFrameCodeService;
	@Value("${trustoner.supplier.id}")
	private Long trustonerSupplierId;

	@Override
	public void update(Observable o, Object arg) {
		// String orderCode = arg != null ? arg.toString() : null;
		OrderPayModel model = arg != null ? (OrderPayModel) arg : null;
		if (model == null || model.getOrderId() == null) {
			logger.error(o.getClass().getName() + ": orderCode 为空");
		}
		int count = ygOrderService.countDetailBySupplierId(model.getOrderId(), trustonerSupplierId);
		if (count == 0) {
			return;
		}
		if (o instanceof OrderPaySuccessObservable) {
//			 Date excuteTime = DateConvertUtils.addMinute(new Date(), 12 *
//			 60);
//			 scheduleJobService.addTrustonePushOrderJob(model.getOrderId().toString(),
//			 excuteTime, "orderpaysuccess");

		} else if (o instanceof OrderCancelObservable) {
			// TODO
		}

	}
	
	

}
